//密码控件类 
var panelIdDivID;
function PwdControl(id,panelId,width,height,uuid){
	this.id=id;
	this.uuid=uuid;
	this.panel=$("#"+panelId);
	this.width=width;
	this.height=height;
	
	this.obj;
	
	//密码密文
	this.pwd;
	
	//纯密码密文
	this.purePwdCipher;
	
	
	this.init();
	panelIdDivID = panelId;
	//this.finger();
}

PwdControl.version=null;
PwdControl.instance=null;

PwdControl.checkVersion=function(){
	//检查环境
	if(!PwdControl.version){
		try{
			var pwd=PwdControl.instance.obj.GetPwdText();
			if (pwd!='@'){
				PwdControl.version="1.0";
				//alert("请升级安全控件!");
			}
			else{
				PwdControl.version="2.0";
			}
			
		}catch(e){
			PwdControl.version="0.0";
            if($("#"+panelIdDivID+"Tip").length  >0 ){
                $("#"+panelIdDivID).hide();
                $("#SEditCtrlObjpassword").hide();
                $("#"+panelIdDivID+"Tip").show();
            }
		}
	}	
};

PwdControl.prototype.init=function(){
    try{
        //创建对象
        this.initObj();

        //创建表单项
        var h='<input type="hidden" name="'+this.id+'" id="'+this.id+'" />';
        this.panel.before(h);

        if(!PwdControl.instance){
            PwdControl.instance=this;
            setTimeout('PwdControl.checkVersion()',300);
        }
    }catch (e){
        //console.log("init-------"+e);
    }

	
};

PwdControl.prototype.initObj=function(){
	//删除object
	if($("#SEditCtrlObj"+this.id)){
		$("#SEditCtrlObj"+this.id).remove();
	}
	
	//创建对象
	var pwdObj;
	//if(window.ActiveXObject){
    if (!!window.ActiveXObject || "ActiveXObject" in window){
		//IE
		pwdObj = document.createElement("object");
		pwdObj.classid="clsid:6A706FBE-687B-42CC-8DF3-94E453B56B08";
	}else{
		//非IE
		pwdObj = document.createElement("embed");
		pwdObj.setAttribute("type","application/npPwdInput");
	}
	
	pwdObj.id='SEditCtrlObj'+this.id;
	pwdObj.width=this.width+'px';
	pwdObj.height=this.height+'px';
	
	
	
	this.panel.html("");
	this.panel.append(pwdObj);	
	this.obj=pwdObj;
};


PwdControl.prototype.encrypt=function(uuid,safe){
	var ok=true;	
	var pwd="";	
	
	if(uuid){
		this.uuid=uuid;
	}
	
	if(PwdControl.version=="2.0"){//新版本
		if(safe==0){
		    pwd=PwdControl.version+"@"+this.obj.GetPwdStr(uuid);
		}else{
			var arr=this.uuid.split("@");
			var uuid=arr[0];
			var ctrlId=arr[1];
					
		    pwd=PwdControl.version+"@"+ctrlId+"@"+this.obj.GetPwdStr(uuid);
		}
		
	}
	else if(PwdControl.version=="1.0"){//老版本	
		pwd=this.obj.GetPwdText();			
	}
	else{
		ok=false;
	}
	
	this.pwd=pwd;
	$("#"+this.id).val(pwd);
	
	
	//alert("version="+PwdControl.version+"\r\n"+pwd);
	return ok;
};

PwdControl.prototype.getPurePwdCipher=function(){
	if(PwdControl.version=="2.0"){//新版本		
		//纯密码密文
		this.purePwdCipher=this.obj.GetPwdStr("");
	}
	else if(PwdControl.version=="1.0"){//老版本		
		this.purePwdCipher=this.obj.GetPwdText();
	}
	
	return this.purePwdCipher;
};

PwdControl.prototype.destroy=function(){
	//删除object
	$("#SEditCtrlObj"+this.id).remove();
	//删除表单项
	$("#"+this.id).remove();
};

PwdControl.prototype.finger= function(){
	if(enable_fingerinfo == '1'){
	    var aa = this.obj.GetFingerPrint().toString();
	    var str ="";
	    for (var i=0 ; i<=aa.length / 2; i++)
	    {
	    	var c = parseInt(aa.substr(i*2 ,2),16).toString(10);
	    	str = str + String.fromCharCode(c);
	    }
    	$("#fingerInfo").val(str);
	}
}


